//
//  BaseManager.m
//  carcareIOS
//
//  Created by ileo on 16/8/25.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "BaseManager.h"
#import "UserHelper.h"
#import "CalendarMgr.h"
#import "AIUserDefaultObject.h"

@interface AIManager : AIUserDefaultObject

@property (nonatomic, copy) NSString *version;
@property (nonatomic, copy) NSString *date;
@property (nonatomic, assign) NSInteger uid;

@end

@implementation AIManager
@end

@interface BaseManager ()

@property (nonatomic, strong) AIManager *aiManager;

@end

@implementation BaseManager

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveAccountLogout) name:USER_LOGOUT object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(check) name:USER_LOGIN object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
        self.aiManager = [[AIManager alloc] initWithIdentification:[NSString stringWithFormat:@"%@",[self class]]];
        [self check];
    }
    return self;
}

-(void)check{
    ReceiveUpdateType updateType = ReceiveUpdateNone;
    if (self.aiManager.uid != USERINFO.userID) {
        self.aiManager.uid = USERINFO.userID;
        updateType = updateType | ReceiveAccountUpdate;
    }
    if (![self.aiManager.version isEqualToString:__APP_V]) {
        self.aiManager.version = __APP_V;
        updateType = updateType | ReceiveVersionUpdate;
    }
    if (![self.aiManager.date isEqualToString:CALENDARMGR.currentDay]) {
        self.aiManager.date = CALENDARMGR.currentDay;
        updateType = updateType | ReceiveDateUpdate;
    }
    [self didReceiveUpdate:updateType];
}

-(void)didReceiveAccountLogout{
}

-(void)didReceiveMemoryWarning{
}

-(void)didReceiveUpdate:(ReceiveUpdateType)updateType{
}

@end
